package com.zeng.nicecore.exception;

import com.zeng.nicecommon.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ControllerAdvice
@Slf4j
public class GlobalExceptionResolver {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object handleException(Exception e) {
        log.error(e.getMessage(), e);
        return ResponseUtil.serviceError("运行异常:" + e.getMessage());

    }

    @ResponseBody
    @ExceptionHandler(NullPointerException.class)
    public Object handleNull(Exception e, HttpServletRequest request,HttpServletResponse response) {
        log.error(e.getMessage(), e);
        return ResponseUtil.serviceError("运行异常:" + e.getMessage());
    }
}
